home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / talinasm.lha / getlockname.asm < prev    next >
Encoding:
Assembly Source File  |  1991-11-03  |  1.8 KB  |  60 lines

  1. ************************************************************************
  2. * GetLockName.asm - gets the name of a lock                            *
  3. * Written August 1988 by Talin                                         *
  4. * Assembly version Oct 1988 by JPearce / Talin                           *
  5. ************************************************************************
  6.  
  7. ; LONG GetLockName(lock,buffer,length)
  8.  
  9.         include 'macros.i'
  10.         include 'exec/memory.i'
  11.         include 'libraries/dosextens.i'
  12.  
  13.         public        _DOSBase
  14.  
  15.         DECLARE     GetLockName            ; GetLockName(lock,buffer,length)
  16.  
  17.         SaveM        a2/a3/d4
  18.  
  19.         moveq        #0,d4                ; result = FALSE
  20.  
  21.         NEW            a3,fib_SIZEOF        ; get storage for FileInfoBlock
  22.         tst.l        d0
  23.         beq.s        scat1                ; out of memory error
  24.  
  25.         move.l        16(sp),d1            ; d1 <-- lock on object
  26.         move.l        a3,d2                ; d2 <-- address of FIB
  27.         CallDos        Examine                ; d0 <-- success
  28.         tst.l        d0
  29.         beq.s        scat2                ; examine failed
  30.  
  31.         lea            fib_FileName(a3),a1    ; a1 <-- address of filename
  32.         move.l        20(sp),a0            ; a0 <-- address of buffer
  33.         move.l        24(sp),d1            ; d1 <-- maximum name laength
  34.         bra.s        2$                    ; start looping
  35.  
  36. 1$        move.b        (a1)+,(a0)+            ; move 1 byte
  37.         beq.s        3$                    ; if NULL, then quit
  38. 2$        dbra        d1,1$                ; loop until no more bytes
  39. 3$        move.b        #0,-1(a0)            ; make sure string NULL terminated!
  40.         moveq        #-1,d4                ; result = TRUE
  41.  
  42. scat2:    DELETE        a3,fib_SIZEOF        ; free memory
  43. scat1:    move.l        d4,d0                ; return result
  44.         RestoreM    a2/a3/d4
  45.         rts
  46.  
  47.         end
  48.  
  49. LONG GetLockName(LOCK lock,char *buffer,LONG length)
  50. {    register struct FileInfoBlock    *fib=NULL;
  51.     register ULONG                    result = FALSE;
  52.  
  53.     unless (fib = AllocMem(sizeof *fib,MEMF_CLEAR))    /* create the file info block */
  54.         return NULL;
  55.     if (result = Examine(lock,fib))                    /* examine file                */
  56.         strn_cpy(buffer,fib->fib_Name,length);        /* fill in date */
  57.     FreeMem(fib,sizeof *fib);                        /* de-alloc fib */
  58.     return result;
  59. }
  60.